package cn.leaf.cloud.banner;

import cn.hutool.core.util.RandomUtil;
import lombok.NonNull;
import org.springframework.boot.SpringBootVersion;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * description: banner 初始化
 *
 * @author twinkle leaf
 * @version v1.0.0
 * @since 2021-11-07 17:11:22
 * slogan: There are no two identical leaves in the world.
 *
 */
public class BannerInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    @Override
    public void initialize(@NonNull ConfigurableApplicationContext applicationContext) {
        if (!(applicationContext instanceof AnnotationConfigApplicationContext)) {

            String[] words = CommonConstants.words;
            int length = words.length;
            int index = RandomUtil.randomInt(0, length - 1);
            String word = words[index];

            Date date = new Date();
            SimpleDateFormat df = new SimpleDateFormat("HH");
            String str = df.format(date);
            int a = Integer.parseInt(str);

            String hello = "";
            if (a >= 0 && a <= 6) {
                hello = "凌晨好，";
            }
            else if (a > 6 && a <= 12) {
                System.out.println("上午好，");
            }
            else if (a > 12 && a < 13) {
                hello = "中午好，";
            }
            else if (a > 13 && a <= 18) {
                hello = "下午好，";
            }
            else if (a > 18 && a <= 24) {
                hello = "晚上好，";
            }

//            int result = new GregorianCalendar().get(GregorianCalendar.AM_PM);
            String logo =
                            "\n" +
                            " ████████╗██╗    ██╗██╗███╗   ██╗██╗  ██╗██╗     ███████╗    ██╗     ███████╗ █████╗ ███████╗" + "\n" +
                            " ╚══██╔══╝██║    ██║██║████╗  ██║██║ ██╔╝██║     ██╔════╝    ██║     ██╔════╝██╔══██╗██╔════╝" + "\n" +
                            "    ██║   ██║ █╗ ██║██║██╔██╗ ██║█████╔╝ ██║     █████╗      ██║     █████╗  ███████║█████╗" + "\n" +
                            "    ██║   ██║███╗██║██║██║╚██╗██║██╔═██╗ ██║     ██╔══╝      ██║     ██╔══╝  ██╔══██║██╔══╝" + "\n" +
                            "    ██║   ╚███╔███╔╝██║██║ ╚████║██║  ██╗███████╗███████╗    ███████╗███████╗██║  ██║██║" + "\n" +
                            "    ╚═╝    ╚══╝╚══╝ ╚═╝╚═╝  ╚═══╝╚═╝  ╚═╝╚══════╝╚═════╝    ╚══════╝╚══════╝╚═╝  ╚═╝╚═╝" + "\n" + "\n" +
                            "spring boot version:" + SpringBootVersion.getVersion() + "\n" +
                            hello + System.getProperty("user.name") + " ❤ 愿你有个好心情 ❤ " +  "\n" +
                            word + "\n";

            System.out.println(logo);
        }
    }
}
